package com.huluobo.document

import com.huluobo.lib_base.BaseViewModel
import com.huluobo.lib_base.HttpType
import com.huluobo.lib_base.Res
import com.huluobo.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/2/6.
 */
@HiltViewModel
class DocViewModel @Inject constructor(private val docRepo: DocRepo) : BaseViewModel<DocIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is DocIntent.getDoc -> {
                httpRequest(docRepo.getDoc() as Flow<Res<Any>>)
            }

            is DocIntent.scanFile -> {
                scanFile(it.file)
            }

            is DocIntent.deleteDoc -> {
                httpRequest(docRepo.deleteDoc(it.id) as Flow<Res<Any>>, HttpType.DELETE)
            }

            is DocIntent.uploadDoc -> {
                httpRequest(
                    docRepo.uploadDoc(
                        it.name,
                        it.path,
                    ) as Flow<Res<Any>>,
                    HttpType.UPLOAD
                )
            }
        }
    }
}